﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Universe.VectorImage
{
    using System.Drawing;
    using System.Drawing.Drawing2D;

    public class Renderer
    {
        public static void Render(Graphics g, IEnumerable<SimpleLine> lines, params Pen[] pens)
        {
            foreach (var line in lines)
            {
                var pen = line.Pen >= pens.Length ? pens[0] : pens[line.Pen];
                g.DrawLine(pen, line.X1, line.Y1, line.X2+1, line.Y2+1);
            }
        }

        public static GraphicsPath GetGraphicsPath(IEnumerable<SimpleLine> lines)
        {
            GraphicsPath ret = new GraphicsPath();
            Point? prev = null;
            foreach (var line in lines)
            {
                var next = new Point(line.X1, line.Y1);
                if (prev != null && !prev.Value.Equals(next))
                    ret.CloseFigure();

                ret.AddLine(line.X1, line.Y1, line.X2, line.Y2);
                prev = new Point(line.X2, line.Y2);
            }
            
            return ret;
        }
    }
}
